package com.cysyz.mylib.commonservice.servicesupport;


import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.cysyz.mylib.dao.BaseDao;
import com.cysyz.mylib.dao.Conds;
import com.cysyz.mylib.dao.engine.PersistenceEngine;
import com.cysyz.mylib.dao.PagingResult;

public abstract class CommonServiceSupport{
	@Resource
	protected BaseDao baseDao;

	public void save(Object entity) {
		baseDao.save(entity);
	}

	public <T> void remove(Class<T> clazz, Serializable entityID) {
		baseDao.remove(clazz, entityID);
	}

	public void removeByCollection(List list) {
		baseDao.removeByCollection(list);
	}

	public void update(Object entity) {
		baseDao.update(entity);
	}

	public <T> T get(Class<T> clazz, Serializable entityID) {
		return baseDao.get(clazz, entityID);
	}

	public <T> long getCount(Class<T> clazz, Conds conds, PersistenceEngine.Query queryForData) {
		return baseDao.getCount(clazz, conds, queryForData);
	}

	public <T> long getCount(Class<T> clazz, PersistenceEngine.Query queryForData) {
		return baseDao.getCount(clazz, null, queryForData);
	}
	
	public <T> long getCount(Class<T> clazz) {
		return baseDao.getCount(clazz);
	}
	
	public <T> List<T> list(Class<T> clazz, boolean isDistinct,
			String[] fieldNames, Conds conds) {
		return baseDao.list(clazz, isDistinct, fieldNames, conds);
	}

	public <T> List<T> list(Class<T> clazz, boolean isDistinct,
			String[] fieldNames) {
		return baseDao.list(clazz, isDistinct, fieldNames);
	}

	public <T> List<T> list(Class<T> clazz, String[] fieldNames, Conds conds) {
		return baseDao.list(clazz, fieldNames, conds);
	}

	public <T> List<T> list(Class<T> clazz, Conds conds) {
		return baseDao.list(clazz, conds);
	}

	public <T> List<T> list(Class<T> clazz) {
		return baseDao.list(clazz);
	}

	public <T> List<T> listCacheAble(Class<T> clazz, boolean isDistinct,
			String[] fieldNames, Conds conds) {
		return baseDao.listCacheAble(clazz, isDistinct, fieldNames, conds);
	}

	public <T> List<T> listCacheAble(Class<T> clazz, String[] fieldNames,
			Conds conds) {
		return baseDao.listCacheAble(clazz, fieldNames, conds);
	}

	public <T> List<T> listCacheAble(Class<T> clazz, Conds conds) {
		return baseDao.listCacheAble(clazz, conds);
	}

	public <T> List<T> listCacheAble(Class<T> clazz) {
		return baseDao.listCacheAble(clazz);
	}

	public <T> PagingResult<T> listPaging(Class<T> clazz, int page,
			int maxresult) {
		return baseDao.listPaging(clazz, page, maxresult);
	}

	public <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds,
			int page, int maxresult) {
		return baseDao.listPaging(clazz, conds, page, maxresult);
	}
	
	public <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds, String queryPrefix, String queryPostfix, 
			int page, int maxresult) {
		return baseDao.listPaging(clazz, conds, queryPrefix, queryPostfix, page, maxresult);
	}

	public <T> PagingResult<T> listPaging(Class<T> clazz, String queryPrefix,
			String queryPostfix, int page, int maxresult) {
		return baseDao.listPaging(clazz, queryPrefix, queryPostfix, page,
				maxresult);
	}

	public PersistenceEngine getPersistenceEngine() {
		return baseDao.getPersistenceEngine();
	}

	public int execute(String ql, List<Object> params) {
		return baseDao.execute(ql, params);
	}

	public int executeSql(String sql, List<Object> params) {
		return baseDao.executeSql(sql, params);
	}

	public <T> List<T> list(String sql, List<Object> params, Class<T> clazz) {
		return baseDao.list(sql, params, clazz);
	}

	public <T> PagingResult<T> listPaging(String sql, List<Object> params,
			Class<T> clazz, int page, int maxresult) {
		return baseDao.listPaging(sql, params, clazz, page, maxresult);
	}

	public <T> long getCount(Class<T> clazz, Conds conds) {
		return baseDao.getCount(clazz, conds);
	}

	public <T> List<T> list(Class<T> clazz, String queryPrefix,
			String queryPostfix) {
		return baseDao.list(clazz, queryPrefix, queryPostfix);
	}

	public <T> List<T> list(Class<T> clazz, String queryPrefix) {
		return baseDao.list(clazz, queryPrefix);
	}

	public Object getSingleResult(String ql, Map<String, Object> paramPlaceAndValues) {
		return baseDao.getSingleResult(ql, paramPlaceAndValues);
	}
	
	public long getCount(String sql, List<Object> params, Class clazz) {
		return baseDao.getCount(sql, params, clazz);
	}

	public <T> List<T> list(Class<T> clazz, Conds conds, String queryPrefix,
			String queryPostfix) {
		return baseDao.list(clazz, conds, queryPrefix, queryPostfix);
	}

	/**
	 * special entity is exist
	 * 
	 * @param clazz
	 * @param id
	 * @return
	 */
	public <T> boolean isExist(Class<T> clazz, String id) {
		Conds conds = new Conds();
		conds.addFilter(clazz.getSimpleName(), "id", id);
		return baseDao.getCount(clazz, conds) > 0;
	}

}
